package com.neusoft.weekreport.component.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.mail.Folder;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

/**
 * @Author liu.jiaming
 * @Create 2022/10/24 16:37
 */

@RestController
public class FileController {

    @PostMapping("/upload")
    public String fileUpload(MultipartFile file, HttpServletRequest request) {
        String a = "";
        //目录
        String path = "H:\\testFile\\标准库\\标准库-200\\标准库-2-1000";
        //原始文件名
        String originName = file.getOriginalFilename();


        File folder = new File(path);
        File[] list = folder.listFiles();
        if (!folder.exists()) {
            folder.mkdirs();
        }
        try {
            file.transferTo(new File(folder,originName));
            a = request.getScheme() + "://" + request.getServerName()
                    + ":" + request.getServerPort() + "/" + path + originName;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return a;
    }



}